<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>isSameOrBefore() | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>isSameOrBefore()</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>isSameOrBefore()</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/query/is-same-or-before/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/05-query/04-is-same-or-before.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().isSameOrBefore(Moment|String|Number|Date|Array);
moment().isSameOrBefore(Moment|String|Number|Date|Array, String);
</code></pre>

							</div>
<p>&#x68C0;&#x67E5;&#x4E00;&#x4E2A; moment &#x662F;&#x5426;&#x5728;&#x53E6;&#x4E00;&#x4E2A; moment &#x4E4B;&#x524D;&#x6216;&#x4E0E;&#x4E4B;&#x76F8;&#x540C;&#x3002;
&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4F1A;&#x88AB;&#x89E3;&#x6790;&#x4E3A; moment&#xFF08;&#x5982;&#x679C;&#x5C1A;&#x672A;&#x89E3;&#x6790;&#xFF09;&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isSameOrBefore(&apos;2010-10-21&apos;);  // true
moment(&apos;2010-10-20&apos;).isSameOrBefore(&apos;2010-10-20&apos;);  // true
moment(&apos;2010-10-20&apos;).isSameOrBefore(&apos;2010-10-19&apos;);  // false
</code></pre>
<p>&#x5982;&#x679C;&#x8981;&#x5C06;&#x7C92;&#x5EA6;&#x9650;&#x5236;&#x4E3A;&#x6BEB;&#x79D2;&#x4EE5;&#x5916;&#x7684;&#x5355;&#x4F4D;&#xFF0C;&#x5219;&#x5C06;&#x5355;&#x4F4D;&#x4F5C;&#x4E3A;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4F20;&#x5165;&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x7528;&#x4E8E;&#x786E;&#x5B9A;&#x7CBE;&#x5EA6;&#xFF0C;&#x4E14;&#x4E0D;&#x4EC5;&#x4EC5;&#x662F;&#x8981;&#x68C0;&#x67E5;&#x7684;&#x5355;&#x4E2A;&#x503C;&#xFF0C;&#x56E0;&#x6B64;&#x4F7F;&#x7528; day &#x5C06;&#x4F1A;&#x68C0;&#x67E5;&#x5E74;&#x4EFD;&#x3001;&#x6708;&#x4EFD;&#x3001;&#x65E5;&#x671F;&#x3002;</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isSameOrBefore(&apos;2009-12-31&apos;, &apos;year&apos;); // false
moment(&apos;2010-10-20&apos;).isSameOrBefore(&apos;2010-12-31&apos;, &apos;year&apos;); // true
moment(&apos;2010-10-20&apos;).isSameOrBefore(&apos;2011-01-01&apos;, &apos;year&apos;); // true
</code></pre>
<p>&#x4E0E; <code>moment#isAfter</code> &#x548C; <code>moment#isSame</code> &#x4E00;&#x6837;&#xFF0C;<code>moment#startOf</code> &#x652F;&#x6301;&#x7684;&#x4EFB;&#x4F55;&#x65F6;&#x95F4;&#x5355;&#x4F4D;&#x4E5F;&#x9002;&#x7528;&#x4E8E; <code>moment#isSameOrBefore</code>&#xFF1A;</p>
<pre><code>year month week isoWeek day hour minute second
</code></pre>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().isSameOrBefore(Moment|String|Number|Date|Array);
moment().isSameOrBefore(Moment|String|Number|Date|Array, String);
</code></pre>

							</div>
<p>Check if a moment is before or the same as another moment. The first argument will be parsed as a moment, if not already so.</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isSameOrBefore(&apos;2010-10-21&apos;);  // true
moment(&apos;2010-10-20&apos;).isSameOrBefore(&apos;2010-10-20&apos;);  // true
moment(&apos;2010-10-20&apos;).isSameOrBefore(&apos;2010-10-19&apos;);  // false
</code></pre>
<p>If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.</p>
<p>As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.</p>
<pre><code class="language-javascript">moment(&apos;2010-10-20&apos;).isSameOrBefore(&apos;2009-12-31&apos;, &apos;year&apos;); // false
moment(&apos;2010-10-20&apos;).isSameOrBefore(&apos;2010-12-31&apos;, &apos;year&apos;); // true
moment(&apos;2010-10-20&apos;).isSameOrBefore(&apos;2011-01-01&apos;, &apos;year&apos;); // true
</code></pre>
<p>Like <code>moment#isAfter</code> and <code>moment#isSame</code>, any of the units of time that are supported for <code>moment#startOf</code> are supported for <code>moment#isSameOrBefore</code>:</p>
<pre><code>year month week isoWeek day hour minute second
</code></pre>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>